👻 Service(OSI L4)為application提供外部訪問的方式,類型有ClusterIP、NodePort及LoadBalancer等,或更進一步映射成DNS名稱訪問(type: externalName),可處理到簡單的訪問情境,但隨著服務規模複雜度上升,每個訪問都需直接對應單個service,會趨於複雜,這時可以利用Ingress(OSI L7)
,進一步根據URL路徑、主機名稱等,做路由轉導
Ingress是管理外部(http, https) ~ 叢集內各個Service的單一窗口,提供負載平衡、SSL及域名
1. ingress controller
2. ingress resource
pathType
取自K8s官網圖片: 根據url傳入不同的application
metadata:
name: ingress-multiple-rule
spec:
rules:
- http:
paths:
- pathType: Exact
path: /profile
backend: # 對應的service
serviceName: profile-service
servicePort: 80
- pathType: Prefix
path: /post
backend:
serviceName: post-service
servicePort: 80
取自K8s官網圖片: 根據domain name決定傳入哪個application
metadata:
name: ingress-multiple-rule
spec:
rules:
- host: profile.ithome-thirty-days.com
http:
paths:
- backend:
serviceName: profile-service
servicePort: 80
- host: post.ithome-thirty-days.com
http:
paths:
- backend:
serviceName: post-service
servicePort: 80
ingress操作指令
kubectl get ingress <name>
kubectl describe ingress <name>
kubectl create ingress <ingress-name> --rule="host/path=service:port